/**
 * Created by Administrator on 2015/12/7.
 */

var totalpage,pagesize,cpage,count,curcount,outstr;
//初始化
cpage = getCpage();
totalpage =11;
pagesize = 5;
outstr = "";
function getCpage(){
    var urlStr=window.location.href;
    var aHref=urlStr.split('/');
    var cpage=aHref[aHref.length-1];
    return cpage;

}
function getPageNum(){
    var cday=new Date();
    var dday=new Date(2015,9-1,1);//指定2015-9-1为起始日期
    var nMs=cday.getTime()-dday.getTime();
    var nD=Math.floor(nMs/(1000*24*60*60));
    return nD;

}
getPageNum();
function gotopage(target)
{
    cpage = target;        //把页面计数定位到第几页
    setpage();
    //reloadpage(target);    //调用显示页面函数显示第几页,这个功能是用在页面内容用ajax载入的情况
}
function setpage()
{
    if(totalpage<=5){        //总页数小于5页
        for (count=1;count<=totalpage;count++)
        {    if(count!=cpage)
        {
            outstr = outstr + "<a href='/menu/top101/page/"+count+"' onclick='gotopage("+count+")'>"+count+"</a>";
        }else{
            outstr = outstr + "<span class='current' >"+count+"</span>";
        }
        }
    }
    if(totalpage>5){        //总页数大于5页
        if(parseInt((cpage-1)/5) == 0)
        {
            for (count=1;count<=5;count++)
            {    if(count!=cpage)
            {
                outstr = outstr + "<a href='/menu/top101/page/"+count+"' onclick='gotopage("+count+")'>"+count+"</a>";
            }else{
                outstr = outstr + "<span class='current'>"+count+"</span>";
            }
            }
            outstr = outstr + "<a href='/menu/top101/page/"+count+"'' onclick='gotopage("+count+")'> > </a>";
        }
        else if(parseInt((cpage-1)/5) == parseInt(totalpage/5))
        {
            outstr = outstr + "<a href='/menu/top101/page/"+(parseInt((cpage-1)/5)*5)+"' onclick='gotopage("+(parseInt((cpage-1)/5)*5)+")'><</a>";
            for (count=parseInt(totalpage/5)*5+1;count<=totalpage;count++)
            {    if(count!=cpage)
            {
                outstr = outstr + "<a href='javascript:void(0)' onclick='gotopage("+count+")'>"+count+"</a>";
            }else{
                outstr = outstr + "<span class='current'>"+count+"</span>";
            }
            }
        }
        else
        {
            outstr = outstr + "<a href='/menu/top101/page/"+(parseInt((cpage-1)/5)*5)+"' onclick='gotopage("+(parseInt((cpage-1)/5)*5)+")'><</a>";
            for (count=parseInt((cpage-1)/5)*5+1;count<=parseInt((cpage-1)/5)*5+5;count++)
            {
                if(count!=cpage)
                {
                    outstr = outstr + "<a href='/menu/top101/page/"+count+"' onclick='gotopage("+count+")'>"+count+"</a>";
                }else{
                    outstr = outstr + "<span class='current'>"+count+"</span>";
                }
            }
            outstr = outstr + "<a href='/menu/top101/page/"+count+"'' onclick='gotopage("+count+")'> > </a>";
        }
    }
    document.getElementById("page-area").innerHTML = "<div id='setpage'><span id='info'>共"+totalpage+"页|第"+cpage+"页<\/span>" + outstr + "<\/div>";
    outstr = "";
}
setpage();    //调用分页